package michal.tablice;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class SixpackGUI extends JFrame {
	static Sixpack sixpack = new Sixpack();
	int button;
	
	
	private JPanel contentPane;
	private JTextField txtPiwoNr_1;
	private JTextField txtPiwoNr_2;
	private JTextField txtPiwoNr_3;
	private JTextField txtPiwoNr_4;
	private JTextField txtPiwoNr_5;
	private JTextField txtPiwoNr_6;
	private JLabel lblStanPiw;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SixpackGUI frame = new SixpackGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SixpackGUI() {
		this.sixpack = sixpack;
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.CENTER);
		panel.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,}));
		
		txtPiwoNr_1 = new JTextField();
		txtPiwoNr_1.setText(sixpack.zawartosc[0][0].getNazwa() + " (" + sixpack.zawartosc[0][0].getPromile() + ") " + "Masa netto: " + sixpack.zawartosc[0][0].getMasaNetto());
		panel.add(txtPiwoNr_1, "4, 2, fill, default");
		txtPiwoNr_1.setColumns(10);
		
		txtPiwoNr_2 = new JTextField();
		txtPiwoNr_2.setText(sixpack.zawartosc[0][1].getNazwa() + " (" + sixpack.zawartosc[0][1].getPromile() + ") " + "Masa netto: " + sixpack.zawartosc[0][1].getMasaNetto());
		panel.add(txtPiwoNr_2, "4, 4, fill, default");
		txtPiwoNr_2.setColumns(10);
		
		txtPiwoNr_3 = new JTextField();
		txtPiwoNr_3.setText(sixpack.zawartosc[0][2].getNazwa() + " (" + sixpack.zawartosc[0][2].getPromile() + ") " + "Masa netto: " + sixpack.zawartosc[0][2].getMasaNetto());
		panel.add(txtPiwoNr_3, "4, 6, fill, default");
		txtPiwoNr_3.setColumns(10);
		
		txtPiwoNr_4 = new JTextField();
		txtPiwoNr_4.setText(sixpack.zawartosc[1][0].getNazwa() + " (" + sixpack.zawartosc[1][0].getPromile() + ") " + "Masa netto: " + sixpack.zawartosc[1][0].getMasaNetto());
		panel.add(txtPiwoNr_4, "4, 8, fill, default");
		txtPiwoNr_4.setColumns(10);
		
		txtPiwoNr_5 = new JTextField();
		txtPiwoNr_5.setText(sixpack.zawartosc[1][1].getNazwa() + " (" + sixpack.zawartosc[1][1].getPromile() + ") " + "Masa netto: " + sixpack.zawartosc[1][1].getMasaNetto());
		panel.add(txtPiwoNr_5, "4, 10, fill, default");
		txtPiwoNr_5.setColumns(10);
		
		txtPiwoNr_6 = new JTextField();
		txtPiwoNr_6.setText(sixpack.zawartosc[1][2].getNazwa() + " (" + sixpack.zawartosc[1][2].getPromile() + ") " + "Masa netto: " + sixpack.zawartosc[1][2].getMasaNetto());
		panel.add(txtPiwoNr_6, "4, 12, fill, default");
		txtPiwoNr_6.setColumns(10);
		
		lblStanPiw = new JLabel("Stan Piw: 6");
		panel.add(lblStanPiw, "4, 14");
		
		final JButton btnWezPiwo = new JButton("Wez Piwo");
		btnWezPiwo.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				button++;
				wezPiwo();
				if(button==6){
					btnWezPiwo.setVisible(false);
				}
				
			}
		});
		panel.add(btnWezPiwo, "4, 16");
	}
	void wezPiwo(){
		if(button == 1){
			txtPiwoNr_1.setEnabled(false);
			lblStanPiw.setText("Stan Piw: 5");
		}
		else if (button == 2){
			txtPiwoNr_1.setEnabled(false);
			txtPiwoNr_2.setEnabled(false);
			lblStanPiw.setText("Stan Piw: 4");
		}
		else if (button == 3){
			txtPiwoNr_1.setEnabled(false);
			txtPiwoNr_2.setEnabled(false);
			txtPiwoNr_3.setEnabled(false);
			lblStanPiw.setText("Stan Piw: 3");
		}
		else if (button == 4){
			txtPiwoNr_1.setEnabled(false);
			txtPiwoNr_2.setEnabled(false);
			txtPiwoNr_3.setEnabled(false);
			txtPiwoNr_4.setEnabled(false);
			lblStanPiw.setText("Stan Piw: 2");
		}
		else if (button == 5){
			txtPiwoNr_1.setEnabled(false);
			txtPiwoNr_2.setEnabled(false);
			txtPiwoNr_3.setEnabled(false);
			txtPiwoNr_4.setEnabled(false);
			txtPiwoNr_5.setEnabled(false);
			lblStanPiw.setText("Stan Piw: 1");
		}
		else if (button == 6){
			txtPiwoNr_1.setEnabled(false);
			txtPiwoNr_2.setEnabled(false);
			txtPiwoNr_3.setEnabled(false);
			txtPiwoNr_4.setEnabled(false);
			txtPiwoNr_5.setEnabled(false);
			txtPiwoNr_6.setEnabled(false);
			lblStanPiw.setText("Nie ma wiecej piw milordzie");
		}
	}
}
